import os
import win32api

import time
import win32con


# 打开记事本程序，在后台运行，即显示记事本程序的窗口
# win32api.ShellExecute(0, 'open', 'notepad.exe', '','',0)
# # 打开记事本程序，在前台运行
# win32api.ShellExecute(0, 'open', 'notepad.exe', '','',1)
# # 向记事本传递参数，打开python.txt
# win32api.ShellExecute(0, 'open', 'notepad.exe', 'python.txt','',1)
# 在默认浏览器中打开http://www.python.org网站

# win32api.ShellExecute(0, 'open', 'http://www.python.org', '','',1)
# 在默认的媒体播放器中播放E:\song.wma
# win32api.ShellExecute(0, 'open', 'E:\\song.wma', '','',1)
# # 运行位于E:\book\code目录中的MessageBox.py脚本
# win32api.ShellExecute(0, 'open', 'E:\\book\\code\\MessageBox.py', '','',1)


#模拟鼠标左键点击
def mouse_click(x, y):
    win32api.SetCursorPos([x, y])
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)

# 模拟鼠标右键点击
def mouse_right_click(x, y):
    win32api.SetCursorPos([x, y])
    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
    win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)

# 移动鼠标
def move_mouse():
    win32api.mouse_event(win32con.MOUSEEVENTF_MOVE,1095,542,1414,452)

# 实时获取鼠标在屏幕上的坐标
def get_mouse_position():
    try:
        while True:
            print("Press Ctrl-C to end")
            x, y = win32api.GetCursorPos()  # 返回鼠标的坐标
            posStr = "Position:" + str(x).rjust(4) + ',' + str(y).rjust(4)
            print(posStr)  # 打印坐标
            time.sleep(0.2)
            os.system('cls')  # 清楚屏幕
    except  KeyboardInterrupt:
        print('end....')

# 打开某个程序
def execute_exe(path):
    win32api.ShellExecute(0, 'open', path, '', '', 0)



if __name__ =='__main__':
    path = r'E:\work\first_QT\dist\huiulv_main.exe'
    # mouse_right_click(1702,139)
    # execute_exe(path)
    # move_mouse()
    # get_mouse_position()
    # win32api.MessageBox(0, "Hello PYwin32", "MessageBox", win32con.MB_OK | win32con.MB_ICONWARNING)

    import win32gui
    win32gui.FindWindow('1','2')